package com.hwh.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hwh.serviceIm.BuyersServiceImpl;
import com.hwh.vo.Buyers;

public class BuyLoginController extends HttpServlet{

	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
	         throws ServletException, IOException {
       super.doPost(req, resp);
   }

	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		// 获取前台form表单的input输入框
		String buy_name = req.getParameter("buy_name");
		String buy_pwd = req.getParameter("buy_pwd");
		
		Buyers buy = new Buyers();
		buy.setBuy_name(buy_name);
		buy.setBuy_pwd(buy_pwd);
		BuyersServiceImpl bsi = new BuyersServiceImpl();
		Buyers b = bsi.buyerLogin(buy);
		HttpSession session = req.getSession();
		session.setAttribute("Buyers", b);
		
		System.out.println(buy_name);
		System.out.println(buy_pwd);
		
		if (b.getBuy_name() != null) {
			// 返回的不是空值,重定向到登录成功界面
			req.getRequestDispatcher("buyindex.jsp").forward(req, resp);
		} else {
			req.getRequestDispatcher("buylogin.jsp").forward(req, resp);
		}
	}
	
}
